import { Component, Label, UITransform, Vec3, _decorator, tween } from "cc";

const { ccclass, property } = _decorator;

@ccclass('ShowTip')
export class ShowTip extends Component {
	
	@property(Label)
	label: Label = null!;

	private m_bInit: boolean = false;
	private m_szMsg: string = ' ';

	public set szMsg(param: string) {
		this.m_szMsg = param;
		if (this.m_bInit) {
			this.showTip();
		}
	}

	start () {
		this.m_bInit = true;
		this.showTip();
	}

	private showTip() {
		
		this.label.string = this.m_szMsg;
		this.label.updateRenderData(true);
		// this.node.getComponent(UITransform).setContentSize(this.label.getComponent(UITransform).width + 20, 30);
		tween().target(this.node).by(1.0, { position: new Vec3(0, 100, 0) }).call(() => {
			this.node.removeFromParent();
			
		}).start();
	}
}
